package net.qhzw.geologr5.gis.service.system.controller;


import net.qhzw.geologr5.gis.common.framework.utils.JsonResult;
import net.qhzw.geologr5.gis.service.system.query.BorrowQuery;
import net.qhzw.geologr5.gis.service.system.service.BorrowService;
import net.qhzw.geologr5.gis.service.system.service.ProjectTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/***
 * 借阅管理
 */
@RestController
@RequestMapping("borrow")
public class BorrowController {

    @Value("${addressDoc}")
    private String addressDoc;

    @Autowired
    private BorrowService borrowService;

    @Autowired
    private ProjectTypeService projectTypeService;


    /***
     * @param map
     * queryFlag:"projectType,dictSoftnail,specialty"
     *            projectType:项目类型
     *            dictSoftnail:软件分类
     *            specialty:专业类别
     *            project:项目数据
     *            pointType:点位数据
     *            mapIcon: 项目地图图例查看
     *             user : 查询用户
     *
     * @return
     */
    @GetMapping("selectCodeBox")
    public JsonResult getProjectType(@RequestParam Map<String, String> map) {
        return projectTypeService.getProjectType(map);
    }


    /****
     * 查询订阅管理
     * @param query
     * @return
     */
    @GetMapping("findBorrow")
    public JsonResult findBorrow(BorrowQuery query) {
        return borrowService.findBorrow(query);
    }


    /***
     * 借阅审核
     */
    @PutMapping("/audit")
    public JsonResult audit(@RequestBody BorrowQuery query) {
        return borrowService.audit(query);
    }


    /***
     * 借阅单下载
     * @return
     */
    @PostMapping("/print/{id}")
    public JsonResult print(@PathVariable("id") String id) {
        return borrowService.print(id);
    }


    /***
     * 借阅审核单上传
     */
    @PostMapping("/upload")
    public JsonResult upload(@RequestParam("file") MultipartFile file, BorrowQuery query) {
        return borrowService.upload(file, query);
    }


    /***
     * 借阅审核单下载
     * @return
     */
    @RequestMapping("download/{id}")
    public JsonResult download(HttpServletResponse response, @PathVariable("id") String id) {
        return borrowService.download(response, id);
    }


    /***
     * 申请文件目录
     * @param id
     * @return
     */
    @GetMapping("findBorrowDetails")
    public JsonResult findBorrowDetails(@RequestParam String id) {
        return borrowService.findBorrowDetails(id);
    }

    /***
     * 申请文件目录 下载
     * @param id
     * @return
     */
    @PostMapping("appFileCtlgDownload")
    public JsonResult appFileCtlgDownload(@RequestParam Integer id) {
        return borrowService.appFileCtlgDownload(id);
    }




}
